#include "processbar.h"
#include <string.h>
//void ForTest()
//{
//    printf("this is for test\n");
//    printf("this is for test\n");
//    printf("this is for test\n");
//    printf("this is for test\n");
//    printf("this is for test\n");
//    printf("this is for test\n");
//}
const double bandwidth = 1024*1024*1.0;
#define Length 101
#define Style '#'
const char*lable="|/-\\";
void ProcBar(double filesize,double current)
{
    char bar[Length];
    memset(bar,'\0',sizeof(bar));
    double rate=(current*100.0)/filesize;
    int loop_count =(int)rate;
    int cnt = 0;
    int len=strlen(lable);
    while(cnt<=loop_count)
    {
        //0到一百闭区间，不是101,打印101次吗
        bar[cnt++] = Style;
    }
        printf("[%-100s][%.1lf%%][%c]\r",bar,rate,lable[cnt%len]);
        fflush(stdout);
}

void download(double filesize,callback ob)
{
    double current=0.0;
    printf("download begin,current:%lf\n",current);
    while(current<=filesize)
    {
        ob(filesize,current);
        usleep(10000);
        current+=bandwidth;
    }
    printf("\ndownload done,filesize:%lf\n",filesize);
}











